<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Aplicantes</title>

<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/gen-style.css"
	type="text/css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/mkv/jquery-ui.css"
	type="text/css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/ui.jqgrid.css"
	type="text/css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/makovo-style.css"
	type="text/css" />

<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/jquery-2.1.3.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/gen.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/inegi.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/ui/jquery.jqGrid.src.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/spin.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/auxiliares.js"></script>

<script type="text/javascript">
	// 	if (validaSesion("${sessionScope.LoginMenu}"))
	// 		document.location = "index.jsp";
	$(document).ready(function() {
		// 						if (validaSesion("${sessionScope.LoginMenu}"))
		// 							document.location = "index.jsp";

		var mPag = 0;
		var mPageSize = 50;
		var mTotal = 100;

		var mCall = new Gen.AjaxCall();

		$('#export').click(function() {
			/*var state = $('#state').val() ;
			var city = $('#city').val();
			if(validate())
			{
				var info = "state=" + state + "&city=" + city;*/
				window.open('<%=request.getContextPath()%>/tareas/docsmissing.jsp');
			/*}
			else
				alert("");*/
		});
		
		$('#prev').click(function() {
			if (mPag <= 0)
				return;

			mPag -= 1
			getDocReport(mPag, setHeader)
		});

		$('#next').click(function() {
			if (((mPag + 1) * mPageSize) >= mTotal)
				return;

			mPag += 1
			getDocReport(mPag, setHeader)
		});

		$('#tblDocs').jqGrid({
			datatype : "local",
			height : "auto",
			width : 1000,
			caption : "Listado de clientes",
			rowNum : 1000,
			rowList : [ 1000, 2000 ],
			colNames : [ 'CURP', 'Nombre', 'CURP', 'ID', 'NAC', 'MAT', 'ING', 'DOM', 'ESC', 'INM', 'GEO', 'CUIS' ],
			colModel : [ {
				name : 'curp',
				index : 'curp',
				width : 100,
				key : true
			}, {
				name : 'name',
				index : 'name',
				width : 200,
				formatter : formatterApplicant
			}, {
				name : 'curp',
				index : 'curp',
				width : 40,
				formatter : formatterCurp
			}, {
				name : 'id',
				index : 'id',
				width : 40,
				formatter : formatterId
			}, {
				name : 'nac',
				index : 'nac',
				width : 40,
				formatter : formatterNac
			}, {
				name : 'mat',
				index : 'mat',
				width : 40,
				formatter : formatterMat
			}, {
				name : 'ing',
				index : 'ing',
				width : 40,
				formatter : formatterIng
			}, {
				name : 'dom',
				index : 'dom',
				width : 40,
				formatter : formatterDom
			}, {
				name : 'esc',
				index : 'esc',
				width : 40,
				formatter : formatterEsc
			}, {
				name : 'inm',
				index : 'inm',
				width : 40,
				formatter : formatterInm
			}, {
				name : 'geo',
				index : 'geo',
				width : 40,
				formatter : formatterGeo
			}, {
				name : 'cuis',
				index : 'cuis',
				width : 40,
				formatter : formatterCuis
			} ],
			subGrid : false,
			loadComplete : function(request) {

			}
		});

		function refreshGrid(data) {
			$('#tblDocs').jqGrid('clearGridData');
			$('#tblDocs').jqGrid('setGridParam', {
				data : data
			});
			$('#tblDocs').trigger('reloadGrid');
		}

		function formatterApplicant(cellValue, options, rowObject) {
			return rowObject.name + " " + rowObject.lastName + " " + rowObject.secondLastName;
		}

		function formatterCurp(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "curp") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterId(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "ide") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterNac(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "nac") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterMat(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "mat") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterDom(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "dom") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterEsc(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "esc") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterInm(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "inm") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}
		function formatterIng(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "ing") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterGeo(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "geo") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		function formatterCuis(cellValue, options, rowObject) {
			var cl = "rejected"

			if (rowObject.docs[0] != null)
				if (findValue(rowObject.docs, "identifier", "ise") != null)
					cl = "approved"

			return "<span class='" + cl + "'>X</span>";
		}

		var setHeader = function(p) {
			var end = p.pageSize * (mPag + 1);

			mTotal = p.total;
			mPageSize = p.pageSize;

			if (end > mTotal)
				end = mTotal;

			$('#num-end').text(end);
			$('#num-init').text((p.pageSize * mPag)+1);
			$('#num-total').text(p.total);
		}

		function getDocReport(pag, afterfunction) {
			showOverlay(true)

			mCall.post('ajax/GetDocsReport.action', {
				pag : pag
			}, function(u) {
				refreshGrid(u.docs)

				afterfunction(u)
				hideOverlay();
			}, function(er) {
			});
		}

		getDocReport(mPag, setHeader);
	});
</script>
</head>
<body>
	<div style="width: 1100px; margin: 0 auto">
		<form action="ajax/GetUser">
			<div class="headerMK">
				<div class="logo">
					<span class="hdTitulo">Sistema para Aplicación de Subsidio
						2015</span>
				</div>
				<div
					style="font-size: 0.26em; top: -50px; position: relative; width: 500px; float: right; text-align: right; padding-right: 10px">
					<i>${sessionScope.LoginNombre}</i><b><a
						href="/makovo/paginas/index.jsp"> - Cerrar Sesión</a></b>
				</div>
			</div>
		</form>

		<div class="divContenido">
			<a href="<%=request.getContextPath()%>/paginas/menu.jsp">Regresar
				al menú</a> <br />
			<div style="width: 1000px; margin: 0px auto; padding: 2em;">
				<div style="float: right;">
					<span>Se muestran registros </span> <span id="num-init">0</span> <span>a</span>
					<span id="num-end"></span> <span>de</span> <span id="num-total"></span>
				</div>
				<br> <br>
				<table id="tblDocs">

				</table>
				<br> <br>
				<div>
					<button type="button" style="float: left;" id="prev"
						class="t-btn tiny hor-opening">Página anterior</button>
					<button type="button" style="float: right;" id="next"
						class="t-btn tiny hor-opening">Página siguiente</button>
				</div>
				<button type="button" id="export" class="t-btn tiny hor-opening" style="width: 1000px; margin: 0px auto;">Exportar
					CSV</button>
			</div>
		</div>
	</div>

</body>
</html>